package com.jenkins.test.web.vo;

import com.alibaba.fastjson.JSONObject;

import java.util.*;

/**
 * @version V1.0.0
 * @ClassName: {@link TravelDataUtil}
 * @Description: TravelDataUtil
 * @author: Lanzhou
 * @date: 2021/9/2 9:37
 * @Copyright:2020 All rights reserved.
 */
public class TravelDataUtil {


    private static TravelPageVo result = new TravelPageVo();

    private static final int RESULT_DATA_LEN = 12;


    private static String[] TITLE = {"半夜吃黄连——暗中叫苦",
            "半夜吃甘庶——不知头尾",
            "半衣敲钟——一鸣惊人",
            "半夜过独木桥——步步小心",
            "半天云里打麻雀——空对空",
            "半天云里挂日袋——装疯（凤）",
            "半天云里点灯——高招（照）",
            "半天云里跑马——露马脚",
            "半天打不出喷嚏来——难受",
            "半天云里翻筋斗——终久要落地",
            "半天云里挂锅铲——吵（炒）翻（飞）了天",
            "半天抓云——一句空话",
            "半天云里骑仙鹤——远走高飞",
            "半空中的火把——高明",
            "半路天小差——有始无终",
            "半路上杀出个杨排凤——妈厉害的”r头",
            "绑着腿的青蛙——跳不了啦",
            "磅秤上放粒芝麻——无足轻重",
            "棒打鸭子——呱呱叫",
            "棒打鸳鸯——两分离",
            "棒相当针——粗细不分"};
    private static String[] SLOGAN = {"烟花再美只是瞬间，誓言再美终是废话。",
            "这世上最疼的词叫：原本可以。",
            "有些弦外之音，让人潸然泪下。",
            "饮孤独的酒，吹自由的风，在没有你的日子里做关于你的梦。",
            "此一生，你我皆为应劫而来。",
            "有些人，一旦错过了，真得谢天谢地，锣鼓喧天，鞭炮齐鸣",
            "温柔正确的人总是难以生存，因为这世界既不温柔，也不正确。",
            "所谓靠谱的人，就是凡事有交代，件件有着落，事事有回音。",
            "天空不总是晴朗，阳光不总是闪耀，所以偶尔情绪崩溃下，也无伤大雅。",
            "清风伴我，黎明破晓，愿与你共饮暖酒新茶，共看细水长流。",
            "有些话，你想说自然会说，不想说，听到的也只是假话。",
            "一念放下，万般自在。",
            "多么希望有个人，给我依靠的肩膀",
            "无话不说是我们的曾经，无话可说是我们的结局。",
            "我想帮你准备早餐，和你一起吃晚餐。",
            "你是我口中的蜜糖，永远的甜心。",
            "不管怎么说，路还很长，所以把余生都扔给你也无妨。"};
    private static String[] PRICE = {"199", "299", "359", "128", "688", "1299", "598"};
    private static String[] UNIT = {"起/人", "起/套"};
    private static String[] TYPE = {"私家定制游", "旅行团", "酒店套餐"};
    private static String[] TAG = {"全年可约", "全年专车", "1家1团", "世外桃源", "人间净土", "深度游", "星级酒店", "经典环线", "野奢度假", "小资下午茶", "金牌讲师", "颜值担当"};

    static {
        // 轮播
        result.setBannerList(new ArrayList<String>() {{
            add("http://114.98.238.142:9000/imgcloud/ia_10054.jpg");
            add("http://114.98.238.142:9000/imgcloud/ia_10055.jpg");
            add("http://114.98.238.142:9000/imgcloud/ia_10056.jpg");
            add("http://114.98.238.142:9000/imgcloud/ia_10057.jpg");
            add("http://114.98.238.142:9000/imgcloud/ia_10058.jpg");
        }});

        // 推荐
        Map<String, RecommendVo> recommendList = buildRecommend();
        result.setRecommendList(recommendList);

        // 其他数据
        result.setShanghaiTravelMap(buildData());
    }


    /**
     * 获取所有数据
     *
     * @return
     */
    public static TravelPageVo buildTravelData() {
        return result;
    }


    private static Map<String, RecommendVo> buildRecommend() {
        Map<String, RecommendVo> recommendList = new HashMap<>();
        RecommendVo menu = new RecommendVo();
        menu.setTypUrl("http://114.98.238.142:9000/imgcloud/ia_10061.jpg");
        menu.setImgList(new ArrayList<String>() {{
            add("http://114.98.238.142:9000/imgcloud/ia_10074.jpg");
            add("http://114.98.238.142:9000/imgcloud/ia_10075.jpg");
            add("http://114.98.238.142:9000/imgcloud/ia_10076.jpg");
            add("http://114.98.238.142:9000/imgcloud/ia_10077.jpg");
        }});
        recommendList.put("sortMenu", menu);
        RecommendVo recommend = new RecommendVo();
        recommend.setTypUrl("http://114.98.238.142:9000/imgcloud/ia_10060.jpg");
        recommend.setImgList(new ArrayList<String>() {{
            add("http://114.98.238.142:9000/imgcloud/ia_10001.jpg");
            add("http://114.98.238.142:9000/imgcloud/ia_10002.jpg");
            add("http://114.98.238.142:9000/imgcloud/ia_10003.jpg");
            add("http://114.98.238.142:9000/imgcloud/ia_10004.jpg");
        }});
        recommendList.put("recommend", recommend);
        return recommendList;
    }

    /**
     * 构建数据
     *
     * @return
     */
    private static Map<String, List<TravelVo>> buildData() {
        Map<String, List<TravelVo>> result = new HashMap<>(12);
        String json = "[{\"title\":\"虫虫研学课|公园夜探·偶遇夜间小精灵\",\"slogan\":\"寻找昆虫中的“伪装大师”\",\"price\":\"198\",\"unit\":\"起/人\",\"type\":\"旅行团\",\"tag\":\"亲子研学\",\"imgUrl\":\"http://114.98.238.142:9000/imgcloud/ia_10005.jpg\"},{\"title\":\"逸游·城市漫步系列 | 上海武康路\",\"slogan\":\"一条武康路 半部民国史”\",\"price\":\"159\",\"unit\":\"起/人\",\"type\":\"旅行团\",\"tag\":\"金牌讲师,全程跟拍,小资下午茶\",\"imgUrl\":\"http://114.98.238.142:9000/imgcloud/ia_10006.jpg\"},{\"title\":\"孩子们的快乐星球|星球蜡烛手绘课\",\"slogan\":\"什么是快乐星球？和爸爸麻麻一起的守护地球，快乐加倍\",\"price\":\"399\",\"unit\":\"起/人\",\"type\":\"旅行团\",\"tag\":\"亲子互动\",\"imgUrl\":\"http://114.98.238.142:9000/imgcloud/ia_10007.jpg\"},{\"title\":\"有“故事”的盒子|八音盒DIY（节日限定）\",\"slogan\":\"用简单的木料进行大胆的组合，创造独一无二的八音盒\",\"price\":\"199\",\"unit\":\"起/人\",\"type\":\"旅行团\",\"tag\":\"亲子互动\",\"imgUrl\":\"http://114.98.238.142:9000/imgcloud/ia_10008.jpg\"}]";
        List<TravelVo> travelVos = JSONObject.parseArray(json, TravelVo.class);
        for (int i = 0; i < RESULT_DATA_LEN; i++) {
            List<TravelVo> tempVos = new ArrayList<>();
            for (int j = 0; j < 4; j++) {
                TravelVo vo = new TravelVo();
                vo.setTitle(obtainProperty(TITLE, 1));
                vo.setSlogan(obtainProperty(SLOGAN, 1));
                vo.setPrice(obtainProperty(PRICE, 1));
                vo.setUnit(obtainProperty(UNIT, 1));
                vo.setType(obtainProperty(TYPE, 1));
                vo.setTag(obtainProperty(TAG, 3));
                int offset = travelVos.size() * i + j;
                vo.setImgUrl("http://114.98.238.142:9000/imgcloud/ia_1000" + (5 + offset) + ".jpg");
                tempVos.add(vo);
            }
            result.put("http://114.98.238.142:9000/imgcloud/ia_100" + (62 + i) + ".jpg", tempVos);
        }
        return result;
    }

    /**
     * 获取属性
     *
     * @param data
     * @param max
     * @return
     */
    private static String obtainProperty(String[] data, int max) {
        StringBuilder result = new StringBuilder();
        Set<Integer> indexSet = new HashSet<>();
        for (int i = 0; i < max; i++) {
            int index = (int) (Math.random() * data.length);
            if (indexSet.contains(index)) {
                continue;
            }
            indexSet.add(index);
        }
        for (Integer integer : indexSet) {
            String datum = data[integer];
            result.append(datum).append(",");
        }
        return result.substring(0, result.length() - 1);
    }


    public static void main(String[] args) {
        TravelPageVo travelPageVo = buildTravelData();
        List<TravelVo> travelVos = travelPageVo.getShanghaiTravelMap().get("http://114.98.238.142:9000/imgcloud/ia_10062.jpg");
        System.out.println(travelVos);
        System.out.println(JSONObject.toJSONString(travelPageVo));
    }


}
